/**
 * Copyright (C) Skywares Information Technology, LTD. 
 * All Rights Reserved.
 *
 * CommonResult.java created on 2020年1月23日 上午9:22:36 by Lyon Lu
 */
package com.mvc.server.result;

import java.io.Serializable;

/**
 * <pre>
 * Description:
 * 
 * @author Lyon Lu
 * @date 2020年1月23日 上午9:22:36
 *
 * </pre>
 */
public class CommonResult<T> implements Serializable{

	/**
	* @fields serialVersionUID : TODO
	*/
	private static final long serialVersionUID = 4676818138034159100L;
	
	private Integer code;
	private String message;
	private T data;
	
	public CommonResult(){
	}
	
	public CommonResult(ResultCode resultCode){
		this.code = resultCode.getCode();
		this.message = resultCode.getMessage();
	}
	
	public CommonResult(ResultCode resultCode, T data){
		this.code = resultCode.getCode();
		this.message = resultCode.getMessage();
		this.data = data;
	}
	
	public static <T> CommonResult<T> success(){
		
		return new CommonResult<T>(ResultCode.SUCCESS);
	}
	
	public static <T> CommonResult<T> success(T data){
		
		return new CommonResult<T>(ResultCode.SUCCESS, data);
	}
	
	public static <T> CommonResult<T> error(ResultCode resultCode){
		
		return new CommonResult<T>(resultCode);
	}
	
	public static <T> CommonResult<T> error(ResultCode resultCode, T data){
		
		return new CommonResult<T>(resultCode, data);
	}
	
	/**
	 * @return the code
	 */
	public Integer getCode() {
		return code;
	}
	/**
	 * @param code the code to set
	 */
	public void setCode(Integer code) {
		this.code = code;
	}
	/**
	 * @return the message
	 */
	public String getMessage() {
		return message;
	}
	/**
	 * @param message the message to set
	 */
	public void setMessage(String message) {
		this.message = message;
	}
	/**
	 * @return the data
	 */
	public T getData() {
		return data;
	}
	/**
	 * @param data the data to set
	 */
	public void setData(T data) {
		this.data = data;
	}
	
	@Override
	public String toString() {
		return "CommonResult [code=" + code + ", message=" + message + ", data=" + data + "]";
	}
}
